home *** CD-ROM | disk | FTP | other *** search
/ APDL Eductation Resources / APDL Eductation Resources.iso / programs / electronic / rlab / TestMatrix / gearm_r < prev    next >
Encoding:
Text File  |  1994-12-20  |  1.4 KB  |  47 lines

  1. //-------------------------------------------------------------------//
  2.  
  3. // Synopsis:      Gear matrix.
  4.  
  5. // Syntax:        A = gearm ( N , I , J )
  6.  
  7. // Description:
  8.  
  9. //      A is the N-by-N matrix with ones on the sub- and
  10. //      super-diagonals, SIGN(I) in the (1,ABS(I)) position, SIGN(J)
  11. //      in the (N,N+1-ABS(J)) position, and zeros everywhere
  12. //      else. Defaults: I = N, j = -N.
  13.  
  14. //      All eigenvalues are of the form 2*COS(a) and the eigenvectors
  15. //      are of the form [SIN(w+a), SIN(w+2a), ..., SIN(w+Na)]. The
  16. //      values of a and w are given in the reference below. A can have
  17. //      double and triple eigenvalues and can be defective. GEARM(N)
  18. //      is singular. 
  19.  
  20. //      (GEAR is a Simulink function, hence GEARM for Gear matrix.)
  21. //      Reference:
  22. //      C.W. Gear, A simple set of test matrices for eigenvalue programs,
  23. //      Math. Comp., 23 (1969), pp. 119-125.
  24.  
  25. //    This file is a translation of gearm.m from version 2.0 of
  26. //    "The Test Matrix Toolbox for Matlab", described in Numerical
  27. //    Analysis Report No. 237, December 1993, by N. J. Higham.
  28.  
  29. //-------------------------------------------------------------------//
  30.  
  31. gearm = function ( n , i , j )
  32. {
  33.   if (!exist (i)) { i =  n; }
  34.   if (!exist (j)) { j = -n; }
  35.  
  36.   if (!(i != 0 && abs(i) <= n && j != 0 && abs(j) <= n))
  37.   {
  38.     error("Invalid I and J parameters");
  39.   }
  40.   
  41.   A = diag(ones(n-1,1),-1) + diag(ones(n-1,1),1);
  42.   A[1; abs(i)] = sign(i);
  43.   A[n; n+1-abs(j)] = sign(j);
  44.  
  45.   return A;
  46. };
  47.